package servlet.Jamin;

import net.sf.json.JSONObject;
import pojo.Coupon;
import service.impl.CouponServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Timestamp;

@WebServlet(value = "/InsertCoupon")
public class InsertCoupon extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CouponServiceImpl sc = new CouponServiceImpl();
        JSONObject js = new JSONObject();
        Coupon cp = new Coupon();
        PrintWriter out = resp.getWriter();
        cp.setcDescription(req.getParameter("c_description"));
        cp.setcTerm(Integer.parseInt(req.getParameter("c_term")));
        cp.setcVipPrice(Integer.parseInt(req.getParameter("c_vipprice")));
        cp.setcDeadline(Timestamp.valueOf(req.getParameter("c_deadline")));
        int a=sc.insertCoupon(cp);
        if (a==1){
            js.put("insert",true);
        }else{
            js.put("insert",false);
        }
        out.print(js);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
